#!/bin/csh

# script to run the solver

# name of the file that contains the list of machines
set list_of_machines = `grep MACHINE_FILE DATA/Par_file | cut -c 27- `
set my_local_path = `grep ^LOCAL_PATH DATA/Par_file | cut -c 27- `

# read Par_file to get total number of processors needed

set NPROC_XI = `grep NPROC_XI DATA/Par_file | cut -c 27- `
set NPROC_ETA = `grep NPROC_ETA DATA/Par_file | cut -c 27- `

# total number of processors is product of values read
@ numprocessors = $NPROC_XI * $NPROC_ETA

rm -f sources error*txt starttimeloop* timestamp* PI* RECORDHEADERS

if ( -f $list_of_machines ) then
  echo " "
  echo "using machine file $list_of_machines"
  echo " "
  echo "list of active machines:"
  echo " "
  cat $list_of_machines
  echo " "
endif

echo NPROC_XI = $NPROC_XI
echo NPROC_ETA = $NPROC_ETA
echo " "
echo "starting MPI solver on $numprocessors processors"
echo " "
echo "starting run in current directory $PWD"
echo " "
echo "mesh files will be read from directory $my_local_path"
echo " "

#### use this on Beowulf
cd $PWD/bin
mpirun -nolocal -machinefile $list_of_machines -np $numprocessors ./xspecfem3D

#### use this on SGI
# mpirun -np $numprocessors xspecfem3D

#### use this on Compaq Dec Alpha
# dmpirun -np $numprocessors xspecfem3D

